<?php
/**
 * 未完成医嘱数据拉取 模型
 * @authors xiadx (xiadx@zpdchina.com)
 * @date    2017-03-08 14:21:51
 * @version $Id$
 */

class ZhuyuanYizhuUnworkModel extends BaseModel {

	/**
     * 返回给终端的可执行sql语句的字段名称数组
     * @var [type]
     */
    public $_field_arr = ['yizhu_id','zhuyuan_id','yizhu_type','content','start_time','stop_time','yongfa','yongliang','shiyong_danwei','pinlv','zuhao','zhixing_state','meiri_cishu','wancheng_cishu','yongfa_type','kuatian','beizhu','unwork_time','zhuangtai','chushi_state','xiangying_state','modify_time','shenhe_hushi_id'];

    public function ls($user_department, $jsonData = [], $modify_time = '')
    {
    	// 获取住院患者的zhuyuan_id 列表
        $zhuyuan_info_mod = new ZhuyuanBasicInfoModel;
    	$zhuyuan_basic_info = $zhuyuan_info_mod->getZhyuanIdList($user_department, $modify_time);
    	if (empty($zhuyuan_basic_info)) {
    		return [];
    	}
    	// 将二维数组转换为zhuyuan_id的一维数组
    	$zhuyuan_ids = Utility::array_pluck($zhuyuan_basic_info, 'zhuyuan_id');
    	// 查询的字段
    	$field = 'id as yizhu_id,zhuyuan_id,type as yizhu_type,content,start_time,stop_time,yongfa,yongfa_type,ciliang as yongliang,shiyong_danwei,pinlv,zuhao,zhixing_state,yizhu_yongfa_type as yongfa_type,meiri_cishu,wancheng_cishu,beizhu,unwork_time,state as zhuangtai,chushi_state,xiangying_state,modify_time,shenhe_hushi_id';
    	$query = DB::select($field)
    				->from('zhuyuan_yizhu_unwork')
    				->where('zhuyuan_id', 'IN', $zhuyuan_ids)
                    ->and_where("yiyuan_id","=",$this->yiyuan_id);
		if (!empty($jsonData)) {
			$query->and_where('id', 'IN', $jsonData);
		}
		if ($modify_time) {
			$query->and_where('modify_time', '>=', $modify_time);
		}

		return $query->execute()->as_array();
    }


}
